package com.lianziyou.chain.common.email;

import org.cloud.model.TSystemDicItem;
import org.cloud.utils.CollectionUtil;
import org.cloud.utils.SystemDicUtil;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 邮件通知（通知管理员）
 */
public class EmailNoticeUtil {

    public static boolean noticeAdmin(String content){
        try {
            List<TSystemDicItem> dicItemList = SystemDicUtil.single().getDicItemList("EmailNoticeAdminConfig");
            int successCount = 0;
            if (CollectionUtil.single().isNotEmpty(dicItemList)){
                for (TSystemDicItem item : dicItemList) {
                    String email = item.getDicItemValue();
                    if (!StringUtils.isEmpty(email)){
                        EmailUtil.single().sendSimpleMail(email, "SystemNotice", content);
                        successCount++;
                    }
                }
            }
            return successCount > 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
